*************************************************************************************************
*																								*
*						Flexible Wages, Bargaining, and The Gender Gap							*
*						Barbara Biasi and Heather Sarsons										*
*						Appendix Figures														*
*						name file: appendix_figures_repl.do										*
*																								*
*************************************************************************************************

clear all
set more off
set matsize 11000
set maxvar 32000


global user = 2 // 1 = Heather, 2 = Barbara

if $user == 1 {
cd "/Users/sarsons/Dropbox/wisconsin_women/data"
global tab = "/Users/sarsons/Dropbox/wisconsin_women/draft/tables"
global out = "/Users/sarsons/Dropbox/wisconsin_women/out"
global do = "/Users/sarsons/Dropbox/wisconsin_women/do"
global RA = "/Users/sarsons/Dropbox/wisconsin_women/do/calvin"
global data "/Users/sarsons/Dropbox/wisconsin_women/data"
}
if $user == 2 {
cd "~/Dropbox/Research/wisconsin_women/data"
global tab = "~/Dropbox/Research/wisconsin_women/draft/tables"
global out = "~/Dropbox/Research/wisconsin_women/out"
global do = "~/Dropbox/Research/wisconsin_women/do"
global RA = "~/Dropbox/Research/wisconsin_women/do/calvin"
global data = "~/Dropbox/Research/wisconsin_women/data"
}

* Yale colors
global yaleblue = "0 53 107"
global ylb = "40 109 192"
global yo = "189 83 25"
global ylight = "217 233 242"
global graph = "xlabel(,grid glp(dot) glc(gs10) tlc(gs10)) ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"
global graphbar = "ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"
timer on 1
do $do/QJE_R1/preamble_revision.do
timer off 1
timer list 1

replace logsalary = logsalary * 100
	global itt = "i.dist_itt i.dist_itt#i.postexp i.totalexp i.totalexp#i.postexp i.master i.master#i.postexp i.phd i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	global expD = "i.district_code i.district_code#i.postexp i.district_code#i.totalexp i.district_code#i.totalexp#i.postexp i.district_code#i.master i.district_code#i.master#i.postexp i.district_code#i.phd i.district_code#i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	g reltime = year-extension
	g endtime = 1 if reltime==3
	g starttime = 1 if reltime==-3
	bys id: egen fullstart = max(starttime) 
	by id: egen fullend = max(endtime)
	g balanced3 = (fullstart==1&fullend==1)
	drop endtime starttime fullstart fullend	
	g district2010 = district_code if year==2010
	bys id: egen dist_itt = max(district2010)
	drop district2010
	tempvar x
	g `x' = entry == 1 & totalexp == 1 & year <= 2011
	bysort id: egen entry_pre = max(`x')
keep if timex > -6
label var zero "0"

*-------------------------> 		Appendix file		<-------------------------*

*--> Figure A2: Raw salaries, districts with missing expiration
preserve
drop femx_* fem_*
tab year, gen(T)
forvalues t = 1/`r(r)' {
gen fem_`t' = female * T`t'
}
replace salary_n = salary_n / 1000
reg salary_n T1-T`r(r)' fem_* if expire == ., cluster(district_code)
local df = `e(df_r)'
gen sd = .
qui tab year
forvalues t = 1/`r(r)' {
replace sd = invttail(`df'-1,0.025)*(_se[fem_`t']) if T`t' == 1
}
keep if Extension > 2012 & Extension != .
collapse salary_n sd, by(female year)
gen up = salary + sd if female == 1
gen down = salary - sd if female == 1
twoway 	(rarea up down year if female == 1, fcolor("$yo % 30") lcolor(white)) ///
		(connected salary year if female == 1, color("$yo") lw(thick) lp(solid)) ///
		(connected salary year if female == 0, color("$ylb") lw(thick) lp(dash)) ///
		if year > 2007, legend(order(2 "women" 3 "men") pos(6)  row(1) region(lwidth(none))) $graph ///
		xtitle("year") ytitle("salary ($1,000)")  xlabel(2008(1)2016) ylabel(45(5)60)  xsize(6)
graph export "$out/salary_raw_year_extmissing.png", replace
restore	


*--> Figure A3: Agreements, by assumption
do $do/QJE_R1/replication/agreements_assumptions.do


*--> Figure A4: Gender gap, by district type

* Panel A) 
preserve
eststo baseline_ext_pp: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if timex > -7 & pp == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo baseline_ext_ss: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if timex > -7 & pp == 0, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(baseline_ext_pp, label("no-schedule") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(baseline_ext_ss, label("schedule") lcolor("$ylb") lw(thick) lp(dash) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 zero femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(5.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(row(1) pos(6) region(lwidth(none)))
graph export "$out/gap_bypp_ext_repl.png", replace

* Panel B)
gen expclass = totalexp
replace expclass  = 40 if expclass > 40 & expclass != .
qui tab expclass
forvalues e = 1 / `r(r)' {
local z = `e'
gen fem_exp`z' =  female * (expclass == `z')
gen post_exp`z' =  postext * (expclass == `z')
gen fem_post_exp`z' =  female * postext * (expclass == `z')
gen fem_post_exp_pp`z' =  female * postext * (expclass == `z') * pp
replace fem_exp`z' = . if expclass == .
replace post_exp`z' = . if expclass == .
replace fem_post_exp`z' = . if expclass == .
}
order fem_exp*, last
order post_exp*, last
order fem_post_exp*, last
gen master_  = 1 - master
global expcontr = "post_exp2 post_exp5-post_exp40  fem_exp2 fem_exp5-fem_exp40  fem_post_exp2 fem_post_exp5-fem_post_exp40"
eststo baseline_ext_pp: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female c.master_#c.female c.master_#c.postext c.master_#c.female#c.postext $expcontr if timex > -7 & pp == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo baseline_ext_ss: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female c.master_#c.female c.master_#c.postext c.master_#c.female#c.postext  $expcontr if timex > -7 & pp == 0, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(baseline_ext_pp, label("no-schedule") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(baseline_ext_ss, label("schedule") lcolor("$ylb") lw(thick) lp(dash) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 zero femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(5.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(row(1) pos(6) region(lwidth(none))) // title("3 yrs exp. omitted", size(med))
graph export "$out/gap_bypp_ext_returns_yr3_4_master_repl.png", replace
restore


*--> Figure A6: Gap by management gender

*-> Principal
preserve
label var zero "-1"
eststo d1: reghdfe logsalary femx_5-femx_8 zero femx_10-femx_15 female if male_princ_year == 1, a($exp i.extension##i.year ) vce(cluster district_code)
eststo d2: reghdfe logsalary femx_5-femx_8 zero femx_10-femx_15 female if male_princ_year == 0, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(d2, lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))  ///
			(d1, fcolor(none) lcolor("$ylb") lw(thick) fcolor(none) lp(dash) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))   ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_10 femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension") legend(title("gender of principal at CBA expiration", size(medium)) ///
			 order(2 "female" 4 "male") row(1) region(lwidth(none)) pos(6)) $graph
graph export "$out/gap_byprincipal_pre_repl.png", replace

*-> Superintendent
eststo male: reghdfe logsalary femx_5-femx_8 zero femx_10-femx_15 female if male_super_year == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo fem:  reghdfe logsalary femx_5-femx_8 zero femx_10-femx_15 female if male_super_year == 0, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(fem, lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(male, lcolor("$ylb") lw(thick) fcolor(none) mcolor("$ylb") lp(dash) recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_10 femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  legend(title("gender of superintendent at CBA expiration", size(medium)) ///
			 order(2 "female" 4 "male") row(1) region(lwidth(none)) pos(6)) $graph
graph export "$out/gap_bysuper_pre_repl.png", replace
restore


*--> Figure A7: Robustness
* panel (a)
preserve
eststo rob_entrypre: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if entry_pre == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo rob_balance: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if balanced3==1, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(rob_entrypre, label("Entrants 2007-11") color("$ylb") lw(thick) lp(dash) recast(connect) ciopts(recast(rcap) color("$ylb")))   ///
			(rob_balance,  label("Balanced panel") color("$yo") lw(thick) recast(connect) ciopts(recast(rcap) color("$yo")))   ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  legend(pos(6) row(1))  
graph export "$out/gap_ext_rob1_repl.png", replace
eststo rob_FE: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a(id $exp i.extension##i.year) vce(cluster district_code)
eststo rob_itt: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a($itt  i.extension##i.year) vce(cluster district_code)
coefplot	(rob_FE,       label( "Teacher FE") lw(thick) color("$yo") recast(connect) ciopts(recast(rcap) color("$yo")))   ///
			(rob_itt,      label("ITT") lw(thick) color("$ylb") lp(dash) recast(connect) ciopts(recast(rcap) color("$ylb")))   ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  legend(pos(6) row(1))  
graph export "$out/gap_ext_rob2_repl.png", replace
restore

* panel (b)
preserve
	global expD = "i.district_code i.district_code#i.postexp i.district_code#i.totalexp i.district_code#i.totalexp#i.postexp i.district_code#i.master i.district_code#i.master#i.postexp i.district_code#i.phd i.district_code#i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
eststo rob_expD: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a($expD i.extension##i.year) vce(cluster district_code)
eststo rob_grade: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a($exp Hgrade#Lgrade#postexp i.extension##i.year) vce(cluster district_code)
coefplot	(rob_expD,  label("District-spec schedule")  lw(thick) color("$yo") recast(connect) ciopts(recast(rcap)  color("$yo")))   ///
			(rob_grade, label("Grade FE") lw(thick) color("$ylb") lp(dash)  recast(connect) ciopts(recast(rcap) color("$ylb")))   ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  legend(pos(6) row(1))  
graph export "$out/gap_ext_rob3_repl.png", replace
restore

* panel (c)
tempfile X
preserve
use ../../wisconsin_teachers/data/datasets/staff_large_withid.dta, clear
keep if pos != 53
keep id filenumber year pos
duplicates drop
drop if file == .
rename pos otherpos
drop id
rename file id
bysort id year: gen n = _n
egen group = group(id year)
reshape wide otherpos, i(group) j(n)
drop group
sort id year
save `X', replace
restore
drop if id == .
merge 1:1 id year using `X'
gen has_otherpos = _m == 3
drop if _m == 2
drop _m

qui tab timex
forvalues n = 1/ `r(r)' {
local z = `n' - 6
gen C_`n' = has_otherpos * (timex == `z')
replace C_`n' = . if timex == .
label var C_`n' "`z'"
}

eststo baseline:  reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a($exp i.extension##i.year) vce(cluster district_code)
eststo extraduty: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female has_otherpos C_1-C_5 C_7-C_11, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(extraduty, label("controlling for extra duties") lw(thick) color("$ylb") recast(connect) ciopts(recast(rcap) color("$ylb")))			 ///
			, vert keep(femx_5 femx_6 femx_7  femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(row(1) pos(6) region(lwidth(none)))
graph export "$out/extraduty_premium_repl.png", replace	


*--> Figure A8(a): Survey, gender distribution
preserve
use teachers_panel_va.dta, clear
keep if year == 2016
rename female gender
gen pop = 1
keep gender pop
save temp.dta, replace
restore
preserve
use survey.dta, clear
keep gender
gen pop = 0
append using temp.dta
reg gender pop, rob
gen up = _b[_cons] + _b[pop] + invttail(`e(df_r)'-1,0.025)*(_se[pop])
gen down = _b[_cons] + _b[pop] - invttail(`e(df_r)'-1,0.025)*(_se[pop])
gen coef = _b[_cons] if pop == 0
replace coef = _b[_cons] + _b[pop] if pop == 1
keep coef pop up down
duplicates drop
label define pop 0 "Survey sample" 1 "Population"
label values pop pop
twoway	(bar coef pop if pop == 0, barwidth(0.6) color("$ylb")) ///
		(bar coef pop if pop == 1, barwidth(0.6) color("$yaleblue")) ///
		(rcap up down pop if pop == 1 , lw(thick) color("$yo")), xtitle(" ") ///
		ytitle("share women") ylabel(0(0.2)1) xlabel(0 1, valuelabel) ///
		legend(off) $graph
graph export "$out/survey_genderdescr_repl.png", replace
restore


*--> Figure A8(b): Survey, age distribution
preserve
use teachers_panel_va.dta, clear
gen tot_pop = 1
keep if year == 2016
gen Age = year - birth
keep if Age >= 20 & Age <= 80
gen age = "less than 25" if Age <= 25
replace age = "26-30" if Age > 25 & Age <= 30
replace age = "31-35" if Age > 30 & Age <= 35
replace age = "36-40" if Age > 35 & Age <= 40
replace age = "41-45" if Age > 40 & Age <= 45
replace age = "46-50" if Age > 45 & Age <= 50
replace age = "51-55" if Age > 50 & Age <= 55
replace age = "56 and above" if Age > 55
keep age
gen pop = 1
sort age
save temp.dta, replace
restore

preserve
use survey.dta, clear
keep age
gen pop = 0
append using temp.dta
egen Age = group(age)
replace Age = 0 if Age == 8
qui tab Age, gen(AGE)
gen up = .
gen down = .
gen coef = .
gen coef_sample = .
gen POP = 1 - pop
forvalues n = 1/8 {
local m = `n' - 1
reg AGE`n' POP, rob
replace up = _b[_cons] + _b[POP] + invttail(`e(df_r)'-1,0.025)*(_se[POP]) if Age == `m'
replace down = _b[_cons] + _b[POP] - invttail(`e(df_r)'-1,0.025)*(_se[POP]) if Age == `m'
replace coef_sample = _b[_cons] + _b[POP] if Age == `m'
replace coef = _b[_cons]  if Age == `m'
}
collapse coef coef_sample up down, by(Age)
label define Age 1	"26-30" 2 "31-35" 3 "36-40" 4 "41-45" 5 "46-50" 6 "51-55" 7 "56 and above" 0 "less than 25"
label values Age Age
gen Age2 = Age + 0.4
label values Age2 Age
sort Age
twoway	(bar coef Age, barwidth(0.4) color("$ylb")) ///
		(bar coef_sample Age2, barwidth(0.4) color("$yaleblue")) ///
		(rcap up down Age2, lw(thick) color("$yo")), xtitle(" ") ///
		ytitle("share women") xlabel(0(1)7, valuelabel labsize(small)) ///
		legend(order(1 "Population" 2 "Sample") region(lwidth(none))) $graph
graph export "$out/survey_agedescr_repl.png", replace
restore

*--> Figure A10: Mobility, men and women
eststo fem: reg mover_d D_5-D_9 D_10 D_11-D_15 if female == 1 & timex > -7, cluster(district_code) noco
eststo male: reg mover_d D_5-D_9 D_10 D_11-D_15 if female == 0 & timex > -7, cluster(district_code) noco
coefplot	(fem, label("women") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(male, label("men") lcolor("$ylb") lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(D_5 D_6 D_7 D_8 D_9 D_10 D_11 D_12 D_13 D_14 D_15) omitted  xline(6.5) ///
			 level(90) ytitle("moving rates") xtitle("time to CBA expiration/extension")  $graph legend(row(1) region(lwidth(none)) pos(6))
graph export "$out/mobility_repl.png", replace



*--> Figure A11: Returns to moving
preserve
	tempvar x
	gen `x' = year if mover_d == 1
	bysort id: egen mover_year = max(`x')
	gen timetomove = year - mover_year
	local x = 1
	qui sum timetomove
	forvalues n = `r(min)'/ `r(max)' {
	gen move`x' = timetomove == `n'
	label var move`x' "`n'"
	local x = `x' + 1
	}
	capt gen zero = 0
	label var zero "-1"

	eststo fem: reghdfe logsalary move5-move8 zero move10-move14 if female == 1 & mover_year > extension & mover_year != .  & timetomove > -5 & timetomove < 4, cluster(district_code) a($exp i.extension##i.year)
	eststo male: reghdfe logsalary move5-move8 zero move10-move14 if female == 0 & mover_year > extension & mover_year != . & timetomove > -5 & timetomove < 4, cluster(district_code) a($exp i.extension##i.year)
	coefplot	(fem, label("women") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
				(male, label("men") lcolor("$ylb") lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
				 , vert keep(move6 move7 move8 zero move10 move11 move12 move13) omitted yline(0, lcolor(gs10) lw(vthin)) xline(4.5) ///
				 level(90) ytitle("conditional salary (100*log)") xtitle("time to move, post-CBA expiration/extension")  $graph legend(row(1) region(lwidth(none)) pos(6)) ylabel(0(2)8)
	graph export "$out/mobility_return_repl.png", replace
restore

*--> Figure A9: Switches

* Panel A)
preserve
capt rename schoolcode school_code
capt egen schoolid = group(district_code school_code)
egen lowgrade_gr = group(lowgrade)
egen highgrade_gr = group(highgrade)
drop if id == .
tsset id year
gen change = 0
gen t = 1
bysort id: gen n = _n						
replace change = 1 if	(lowgrade_gr != l.lowgrade_gr) | (highgrade_gr != l.highgrade_gr)  | ///
						(schoolid != l.schoolid) | (all_elem != l.all_elem) | ///
						(math != l.math) | (read != l.read) | (english != l.english)
replace change = 0 if n == 1
drop n
replace change = . if year == 2006
qui tab timex, gen(T)
reg change T1-T`r(r)' femx_5-femx_15, cluster(district_code)
local df = `e(df_r)'
gen sd = .
qui tab timex
forvalues t = 1/`r(r)' {
	local z = `t' + 4
replace sd = invttail(`df'-1,0.025)*(_se[femx_`z']) if T`t' == 1
}
collapse change sd, by(female timex)
gen up = change + sd if female == 1
gen down = change - sd if female == 1
tab change if timex == -5
twoway	(rarea up down timex if female == 1, fcolor("$yo % 30") lcolor(white)) ///
		(connected change timex if female == 1, color("$yo") lw(thick) lp(solid)) ///
		(connected change timex if female == 0, color("$ylb") lw(thick) lp(dash)) ///
		if timex > -5 , legend(order(2 "women" 3 "men") region(lwidth(none)) pos(6) row(1)) $graph ///
		xtitle("time to CBA extension") ytitle("p(changing assignment)") xlabel(-5(1)5) xline(0.5)  ylabel(0.1(0.1)0.40)
graph export "$out/assgn_switch_bygender_repl.png", replace
restore	

* Panel B)
preserve
gen tested = all_elem == 1 | math == 1 | read == 1 | engl == 1
replace tested = 0 if lowgrade == "09" | lowgrade == "10" | lowgrade == "11" | lowgrade == "12"
replace tested = 0 if	highgrade == "01" | highgrade == "02" | highgrade == "03" | highgrade == "K3" ///
						| highgrade == "K4" | highgrade == "KG" | highgrade == "PK"				
drop if id == .
tsset id year
gen change_tested = 0
replace change_tested = 1 if tested == 0 & l.tested == 1					
bysort id: gen n = _n						
replace change_tested = 0 if n == 1
drop n
replace change_tested = . if year == 2006
keep if abs(timex) <= 5
qui tab timex, gen(T)
forvalues t = 1/`r(r)' {
gen Fem_`t' = female * T`t'
}
reg change_t T1-T`r(r)' Fem_*, cluster(district_code)
local df = `e(df_r)'
gen sd = .
qui tab timex
forvalues t = 1/`r(r)' {
replace sd = invttail(`df'-1,0.025)*(_se[Fem_`t']) if T`t' == 1
}
collapse change_t sd, by(female timex)
gen up = change + sd if female == 1
gen down = change - sd if female == 1
twoway	(rarea up down timex if female == 1, fcolor("$yo % 30") lcolor(white)) ///
		(connected change timex if female == 1, color("$yo") lw(thick) lp(solid)) ///
		(connected change timex if female == 0, color("$ylb") lw(thick) lp(dash)) ///
		if timex > -5 , legend(order(2 "women" 3 "men") region(lwidth(none)) pos(6) row(1)) $graph ///
		xtitle("time to CBA extension") ytitle("share tested-->non-tested") ylabel(0(0.01)0.04) xlabel(-4(1)5) xline(0.5)
graph export "$out/tested_switch_bygender_repl.png", replace
restore	



*--> Figure A10(a): Mobility, men and women
eststo fem: reg mover_d D_5-D_9 D_10 D_11-D_15 if female == 1 & tiilimex > -7, cluster(district_code) noco
eststo male: reg mover_d D_5-D_9 D_10 D_11-D_15 if female == 0 & timex > -7, cluster(district_code) noco
coefplot	(fem, label("women") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(male, label("men") lcolor("$ylb") lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(D_5 D_6 D_7 D_8 D_9 D_10 D_11 D_12 D_13 D_14 D_15) omitted  xline(6.5) ///
			 level(90) ytitle("moving rates") xtitle("time to CBA expiration/extension")  $graph legend(row(1) region(lwidth(none)) pos(6))
graph export "$out/mobility_repl.png", replace




*--> Figure A10(b): Returns to moving
preserve
	tempvar x
	gen `x' = year if mover_d == 1
	bysort id: egen mover_year = max(`x')
	gen timetomove = year - mover_year
	local x = 1
	qui sum timetomove
	forvalues n = `r(min)'/ `r(max)' {
	gen move`x' = timetomove == `n'
	label var move`x' "`n'"
	local x = `x' + 1
	}
	capt gen zero = 0
	label var zero "-1"

	eststo fem: reghdfe logsalary move5-move8 zero move10-move14 if female == 1 & mover_year > extension & mover_year != .  & timetomove > -5 & timetomove < 4, cluster(district_code) a($exp i.extension##i.year)
	eststo male: reghdfe logsalary move5-move8 zero move10-move14 if female == 0 & mover_year > extension & mover_year != . & timetomove > -5 & timetomove < 4, cluster(district_code) a($exp i.extension##i.year)
	coefplot	(fem, label("women") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
				(male, label("men") lcolor("$ylb") lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
				 , vert keep(move6 move7 move8 zero move10 move11 move12 move13) omitted yline(0, lcolor(gs10) lw(vthin)) xline(4.5) ///
				 level(90) ytitle("conditional salary (100*log)") xtitle("time to move, post-CBA expiration/extension")  $graph legend(row(1) region(lwidth(none)) pos(6)) ylabel(0(2)8)
	graph export "$out/mobility_return_repl.png", replace
restore



*--> Figure A11(a): Gender gap, elementary vs high school
eststo baseline_el: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if elem == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo baseline_middle: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if middle == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo baseline_high: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if high == 1, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(baseline_el, label("elementary") fcolor(none) lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(baseline_high, label("high") lcolor("$ylb") lw(thick) lp(dash) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(row(1) pos(6) region(lwidth(none)))
graph export "$out/gap_bygrade_repl.png", replace


*--> Figure A11(b): Gender gap, by share of men
preserve
	gen male = 1 - female
	capt rename schoolcode school_code
	bysort district_code school_code year: egen male_year = mean(male)			 
	bysort id: egen mm = mean(male_year) if year <= extension
	bysort id: egen men_mean = max(mm)	
	drop mm
	su men_mean, det
	eststo baseline_highmen: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if men_mean >= 0.25, a($exp i.extension##i.year) vce(cluster district_code)
	eststo baseline_lowmen: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if men_mean < 0.25, a($exp i.extension##i.year) vce(cluster district_code)
	coefplot	(baseline_lowmen, label("low share (at or below median)") lcolor(black) fcolor(none) lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
				(baseline_highmen, label("high share (above median)") lcolor("$ylb") lp(dash) lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
				 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
				 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(title("share of men in school, pre-extension", size(medium)) row(1) pos(6) region(lwidth(none)))
	graph export "$out/gap_bymen_pre_school_repl.png", replace
restore

*---------> Figure A11(c): Schools that lost vs gained men
preserve
gen male = 1 - female
capt rename school_code schoolcode
keep id year male schoolcode district_code
collapse male, by(schoolcode district_code year)
drop if school == . | district == .
egen fake = group(schoolcode district_code)
tsset fake year
gen change = male - l.male if year == 2011 
replace change = male - l2.male if year == 2011 & change == .
replace change = male - l3.male if year == 2011 & change == .
replace change = male - l4.male if year == 2011 & change == .
su change, det
tempvar x
gen `x' = change >= 0 & year == 2011
replace `x' = . if change == .
bysort fake: egen gain = max(`x')
tempvar x
gen `x' = change <= 0.02 & year == 2011
bysort fake: egen lose = max(`x')
keep schoolcode district_code year gain lose
sort schoolcode district_code year
save temp.dta, replace
restore
preserve
capt rename school_code schoolcode
sort schoolcode district_code year
merge m:1 schoolcode district_code year using temp.dta
rm temp.dta
drop if _m == 2 
drop _m
label var zero "0"
eststo baseline_highmen: 	reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if gain == 1, a($exp i.extension##i.year) vce(cluster district_code)
eststo baseline_lowmen: 	reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if lose == 1, a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(baseline_lowmen, label("lost men") lcolor(black) fcolor(none) lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(baseline_highmen, label("gained men") lcolor("$ylb") lp(dash) lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA extension")  $graph legend(title("variation in #men in school", size(medium)) row(1) pos(6) region(lwidth(none)))
graph export "$out/gap_bymen_change_repl.png", replace
restore


*--> Figure A12(a): Gender gap, by share of boys in school
preserve
use enrollment_school.dta, clear
gen shareboy = 100 - percent_of_group_female 
gen P = shareboy if year <= 2011
keep P school_code district_code year
duplicates drop
collapse shareboy_pre = P, by(school_code district_code)
sort school_code district_code
save temp.dta, replace
restore
preserve
capt rename schoolcode school_code
sort school_code district_code
merge m:1 school_code district_code using temp.dta
rm temp.dta
drop if _m == 2
drop _m
eststo baseline_highmen: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if shareboy_pre >= 54 & shareboy_pre != ., a($exp i.extension##i.year) vce(cluster district_code)
eststo baseline_lowmen: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if shareboy_pre < 48 & shareboy_pre != ., a($exp i.extension##i.year) vce(cluster district_code)
coefplot	(baseline_lowmen, label("bottom 5% share of boys") lcolor(black) fcolor(none) lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(baseline_highmen, label("top 5%  share of boys") lcolor("$ylb") lp(dash) lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(title("share of men in school and year", size(medium)) row(1) pos(6) region(lwidth(none)))
graph export "$out/gap_byboy_top5_repl.png", replace



*--> Figure A12(b): Gender gap, controlling for share of boys in school
eststo baseline: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a($exp i.extension##i.year) vce(cluster district_code)
eststo control: reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female, a($exp i.extension##i.year c.shareboy##i.postexp) vce(cluster district_code)
coefplot	(control, label("controlling for share of boys in the school") lcolor(black) fcolor(none) lcolor("$ylb") lw(thick) fcolor(none) mcolor("$ylb") recast(connect) ciopts(lcolor("$ylb %30") recast(rcap)))   ///
			(baseline, label("baseline") lcolor("$ylight") lw(thick) fcolor(none) mcolor("$ylight") recast(connect) ciopts(lcolor("$ylight %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14 femx_15) omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension") $graph legend(row(1) pos(6) region(lwidth(none)))
graph export "$out/gap_byboy_control_repl.png", replace
restore


*--> Figures in Appendix C: Abraham-Sun replications

preserve
*do $do/QJE_R1/replication/AS_gaps_figs.do

	* Difference by Age
	clear all
	
	insheet using $data/weighted_age2.csv, clear 
	
		g l = _n-6

		keep if l<=5
		
		rename b2way_hrs1 FE
		rename biw_hrs1 IW
		rename biw_hrs3 CATT_1
		rename biw_hrs5 CATT_2
		rename biw_hrs7 CATT_3
		rename biw_hrs9 CATT_4	
		
		rename b2way_hrs_old1 FE_old
		rename biw_hrs_old1 IW_old
		rename biw_hrs_old3 CATT_1_old
		rename biw_hrs_old5 CATT_2_old
		rename biw_hrs_old7 CATT_3_old
		rename biw_hrs_old9 CATT_4_old
		
		rename sd1 FE_sd
		rename sd2 IW_sd
		rename sd2011 CATT_1_sd
		rename sd2012 CATT_2_sd
		rename sd2013 CATT_3_sd
		rename sd2014 CATT_4_sd
		
		rename sd1_old FE_old_sd
		rename sd2_old IW_old_sd
		rename sd2011_old CATT_1_old_sd
		rename sd2012_old CATT_2_old_sd
		rename sd2013_old CATT_3_old_sd
		rename sd2014_old CATT_4_old_sd

		foreach var in FE IW FE_old IW_old CATT_1 CATT_2 CATT_3 CATT_4 CATT_1_old CATT_2_old CATT_3_old CATT_4_old {
			g upperCI_`var' = `var' + `var'_sd*1.96
			g lowerCI_`var' = `var' - `var'_sd*1.96
		}

	gen l_IW = l - 0.05
	gen l_IW_old = l + 0.05
	
	twoway rcap upperCI_IW lowerCI_IW l_IW, lpattern(line) mcolor("$ylb % 30") lcolor("$ylb % 30") c(l) ///
		|| scatter IW l_IW , c(l) m(O) xla(-5(1)5) mcolor("$ylb") lcolor("$ylb") lw(thick) ///
		|| rcap upperCI_IW_old lowerCI_IW_old l_IW_old, mcolor("$yo") lcolor("$yo % 30") c(l) ///
		|| scatter IW_old l_IW_old , c(l) m(T) graphreg(fc(white)) lpattern(dash) lw(thick)  mcolor("$yo") lcolor("$yo") ///
			legend(order(2 "Teachers < 25th age pctile" 4 "Teachers > 75th age pctile") pos(6) row(1)) ///
			xtitle("time to CBA expiration/extension") ytitle("Estimate") // scheme(sj)
	graph export $out/AS_age.png, replace

	
	* Experience
	clear all
	
	insheet using $data/weighted_exp2.csv, clear 
	
		g l = _n-6

		keep if l<=5
		
		rename b2way_hrs1 FE
		rename biw_hrs1 IW
		rename biw_hrs3 CATT_1
		rename biw_hrs5 CATT_2
		rename biw_hrs7 CATT_3
		rename biw_hrs9 CATT_4	
		
		rename b2way_hrs_old1 FE_old
		rename biw_hrs_old1 IW_old
		rename biw_hrs_old3 CATT_1_old
		rename biw_hrs_old5 CATT_2_old
		rename biw_hrs_old7 CATT_3_old
		rename biw_hrs_old9 CATT_4_old
		
		rename sd1 FE_sd
		rename sd2 IW_sd
		rename sd2011 CATT_1_sd
		rename sd2012 CATT_2_sd
		rename sd2013 CATT_3_sd
		rename sd2014 CATT_4_sd
		
		rename sd1_old FE_old_sd
		rename sd2_old IW_old_sd
		rename sd2011_old CATT_1_old_sd
		rename sd2012_old CATT_2_old_sd
		rename sd2013_old CATT_3_old_sd
		rename sd2014_old CATT_4_old_sd

		foreach var in FE IW FE_old IW_old CATT_1 CATT_2 CATT_3 CATT_4 CATT_1_old CATT_2_old CATT_3_old CATT_4_old {
			g upperCI_`var' = `var' + `var'_sd*1.96
			g lowerCI_`var' = `var' - `var'_sd*1.96
		}

	gen l_IW = l - 0.05
	gen l_IW_old = l + 0.05
	
	twoway rcap upperCI_IW lowerCI_IW l_IW, lpattern(line) mcolor("$ylb % 30") lcolor("$ylb % 30") c(l) ///
		|| scatter IW l_IW , c(l) m(O) xla(-5(1)5) mcolor("$ylb") lcolor("$ylb") lw(thick) ///
		|| rcap upperCI_IW_old lowerCI_IW_old l_IW_old, mcolor("$yo") lcolor("$yo % 30") c(l) ///
		|| scatter IW_old l_IW_old , c(l) m(T) graphreg(fc(white)) lpattern(dash) lw(thick)  mcolor("$yo") lcolor("$yo") ///
			legend(order(2 "Teachers < 25th exp pctile" 4 "Teachers > 75th exp pctile") pos(6) row(1)) ///
			xtitle("time to CBA expiration/extension") ytitle("Estimate") // scheme(sj)
	graph export $out/AS_exper.png, replace
	
	
	* By principal gender
	clear all
	
	insheet using $data/weighted_princ2.csv, clear 
	
		g l = _n-6

		keep if l<=5
		
		rename b2way_hrs1 FE
		rename biw_hrs1 IW
		rename biw_hrs3 CATT_1
		rename biw_hrs5 CATT_2
		rename biw_hrs7 CATT_3
		rename biw_hrs9 CATT_4	
		
		rename b2way_hrs_old1 FE_old
		rename biw_hrs_old1 IW_old
		rename biw_hrs_old3 CATT_1_old
		rename biw_hrs_old5 CATT_2_old
		rename biw_hrs_old7 CATT_3_old
		rename biw_hrs_old9 CATT_4_old
		
		rename sd1 FE_sd
		rename sd2 IW_sd
		rename sd2011 CATT_1_sd
		rename sd2012 CATT_2_sd
		rename sd2013 CATT_3_sd
		rename sd2014 CATT_4_sd
		
		rename sd1_old FE_old_sd
		rename sd2_old IW_old_sd
		rename sd2011_old CATT_1_old_sd
		rename sd2012_old CATT_2_old_sd
		rename sd2013_old CATT_3_old_sd
		rename sd2014_old CATT_4_old_sd

		foreach var in FE IW FE_old IW_old CATT_1 CATT_2 CATT_3 CATT_4 CATT_1_old CATT_2_old CATT_3_old CATT_4_old {
			g upperCI_`var' = `var' + `var'_sd*1.96
			g lowerCI_`var' = `var' - `var'_sd*1.96
		}

	gen l_IW = l - 0.05
	gen l_IW_old = l + 0.05
	
	twoway rcap upperCI_IW lowerCI_IW l_IW, lpattern(line) mcolor("$ylb % 30") lcolor("$ylb % 30") c(l) ///
		|| scatter IW l_IW , c(l) m(O) xla(-5(1)5) mcolor("$ylb") lcolor("$ylb") lw(thick) ///
		|| rcap upperCI_IW_old lowerCI_IW_old l_IW_old, mcolor("$yo") lcolor("$yo % 30") c(l) ///
		|| scatter IW_old l_IW_old , c(l) m(T) graphreg(fc(white)) lpattern(dash) lw(thick)  mcolor("$yo") lcolor("$yo") ///
			legend(order(2 "Male Principal" 4 "Female Principal") pos(6) row(1)) ///
			xtitle("time to CBA expiration/extension") ytitle("Estimate") // scheme(sj)
	graph export $out/AS_principal.png, replace
	
		
	* By superintedent gender
	clear all
	
	insheet using $data/weighted_super2.csv, clear 
	
		g l = _n-6

		keep if l<=5
		
		rename b2way_hrs1 FE
		rename biw_hrs1 IW
		rename biw_hrs3 CATT_1
		rename biw_hrs5 CATT_2
		rename biw_hrs7 CATT_3
		rename biw_hrs9 CATT_4	
		
		rename b2way_hrs_old1 FE_old
		rename biw_hrs_old1 IW_old
		rename biw_hrs_old3 CATT_1_old
		rename biw_hrs_old5 CATT_2_old
		rename biw_hrs_old7 CATT_3_old
		rename biw_hrs_old9 CATT_4_old
		
		rename sd1 FE_sd
		rename sd2 IW_sd
		rename sd2011 CATT_1_sd
		rename sd2012 CATT_2_sd
		rename sd2013 CATT_3_sd
		rename sd2014 CATT_4_sd
		
		rename sd1_old FE_old_sd
		rename sd2_old IW_old_sd
		rename sd2011_old CATT_1_old_sd
		rename sd2012_old CATT_2_old_sd
		rename sd2013_old CATT_3_old_sd
		rename sd2014_old CATT_4_old_sd

		foreach var in FE IW FE_old IW_old CATT_1 CATT_2 CATT_3 CATT_4 CATT_1_old CATT_2_old CATT_3_old CATT_4_old {
			g upperCI_`var' = `var' + `var'_sd*1.96
			g lowerCI_`var' = `var' - `var'_sd*1.96
		}

	gen l_IW = l - 0.05
	gen l_IW_old = l + 0.05
	
	twoway rcap upperCI_IW lowerCI_IW l_IW, lpattern(line) mcolor("$ylb % 30") lcolor("$ylb % 30") c(l) ///
		|| scatter IW l_IW , c(l) m(O) xla(-5(1)5) mcolor("$ylb") lcolor("$ylb") lw(thick) ///
		|| rcap upperCI_IW_old lowerCI_IW_old l_IW_old, mcolor("$yo") lcolor("$yo % 30") c(l) ///
		|| scatter IW_old l_IW_old , c(l) m(T) graphreg(fc(white)) lpattern(dash) lw(thick)  mcolor("$yo") lcolor("$yo") ///
			legend(order(2 "Male Superintendent" 4 "Female Superintendent") pos(6) row(1)) ///
			xtitle("time to CBA expiration/extension") ytitle("Estimate") // scheme(sj)
	graph export $out/AS_super.png, replace
	
	* By schedule use
	clear all
	
	insheet using $data/weighted_pp2.csv, clear 
	
		g l = _n-6

		keep if l<=5
		
		rename b2way_hrs1 FE
		rename biw_hrs1 IW
		rename biw_hrs3 CATT_1
		rename biw_hrs5 CATT_2
		rename biw_hrs7 CATT_3
		rename biw_hrs9 CATT_4	
		
		rename b2way_hrs_old1 FE_old
		rename biw_hrs_old1 IW_old
		rename biw_hrs_old3 CATT_1_old
		rename biw_hrs_old5 CATT_2_old
		rename biw_hrs_old7 CATT_3_old
		rename biw_hrs_old9 CATT_4_old
		
		rename sd1 FE_sd
		rename sd2 IW_sd
		rename sd2011 CATT_1_sd
		rename sd2012 CATT_2_sd
		rename sd2013 CATT_3_sd
		rename sd2014 CATT_4_sd
		
		rename sd1_old FE_old_sd
		rename sd2_old IW_old_sd
		rename sd2011_old CATT_1_old_sd
		rename sd2012_old CATT_2_old_sd
		rename sd2013_old CATT_3_old_sd
		rename sd2014_old CATT_4_old_sd

		foreach var in FE IW FE_old IW_old CATT_1 CATT_2 CATT_3 CATT_4 CATT_1_old CATT_2_old CATT_3_old CATT_4_old {
			g upperCI_`var' = `var' + `var'_sd*1.96
			g lowerCI_`var' = `var' - `var'_sd*1.96
		}

	gen l_IW = l - 0.05
	gen l_IW_old = l + 0.05
	
	twoway rcap upperCI_IW lowerCI_IW l_IW, lpattern(line) mcolor("$ylb % 30") lcolor("$ylb % 30") c(l) ///
		|| scatter IW l_IW , c(l) m(O) xla(-5(1)5) mcolor("$ylb") lcolor("$ylb") lw(thick) ///
		|| rcap upperCI_IW_old lowerCI_IW_old l_IW_old, mcolor("$yo") lcolor("$yo % 30") c(l) ///
		|| scatter IW_old l_IW_old , c(l) m(T) graphreg(fc(white)) lpattern(dash) lw(thick)  mcolor("$yo") lcolor("$yo") ///
			legend(order(2 "Schedule District" 4 "Non-Schedule District") pos(6) row(1)) ///
			xtitle("time to CBA expiration/extension") ytitle("Estimate") // scheme(sj)
	graph export $out/AS_pp.png, replace
		
	
	* Mobility
	clear all
	
	insheet using $data/weighted_mover3.csv, clear 
	
		g l = _n-6
		keep if l<=5	

		rename b2way_hrs1 FE
		rename biw_hrs1 IW
		rename biw_hrs3 CATT_1
		rename biw_hrs5 CATT_2
		rename biw_hrs7 CATT_3
		rename biw_hrs9 CATT_4	
		
		rename b2way_hrs_m1 FE_m
		rename biw_hrs_m1 IW_m
		rename biw_hrs_m3 CATT_1_m
		rename biw_hrs_m5 CATT_2_m
		rename biw_hrs_m7 CATT_3_m
		rename biw_hrs_m9 CATT_4_m
		
		rename sd1 FE_sd
		rename sd2 IW_sd
		rename sd2011 CATT_1_sd
		rename sd2012 CATT_2_sd
		rename sd2013 CATT_3_sd
		rename sd2014 CATT_4_sd
		
		rename sd1_m FE_m_sd
		rename sd2_m IW_m_sd
		rename sd2011_m CATT_1_m_sd
		rename sd2012_m CATT_2_m_sd
		rename sd2013_m CATT_3_m_sd
		rename sd2014_m CATT_4_m_sd
	
		rename b2way_hrs_old1 FE_old
		rename biw_hrs_old1 IW_old
		rename biw_hrs_old3 CATT_1_old
		rename biw_hrs_old5 CATT_2_old
		rename biw_hrs_old7 CATT_3_old
		rename biw_hrs_old9 CATT_4_old
	
		rename sd1_old FE_old_sd
		rename sd2_old IW_old_sd
		rename sd2011_old CATT_1_old_sd
		rename sd2012_old CATT_2_old_sd
		rename sd2013_old CATT_3_old_sd
		rename sd2014_old CATT_4_old_sd

		foreach var in FE IW FE_m IW_m CATT_1 CATT_2 CATT_3 CATT_4 CATT_1_m CATT_2_m CATT_3_m CATT_4_m FE_old IW_old CATT_1_old CATT_2_old CATT_3_old CATT_4_old {
			g upperCI_`var' = `var' + `var'_sd*1.96
			g lowerCI_`var' = `var' - `var'_sd*1.96
		}

	gen l_IW = l - 0.05
	gen l_IW_old = l + 0.05
	gen l_IW_m	 = l
	
	twoway rcap upperCI_IW lowerCI_IW l_IW, lpattern(line) mcolor("$ylb") lcolor("$ylb %30") c(l) ///
		|| scatter IW l_IW , c(l) m(O) lw(thick)  xla(-5(1)5) mcolor("$ylb") lcolor("$ylb") ///
		|| rcap upperCI_IW_old lowerCI_IW_old l_IW_old, mcolor("$yo") lcolor("$yo %30") c(l) ///
		|| scatter IW_old l_IW_old , c(l) lw(thick)  m(T) graphreg(fc(white)) lpattern(shortdash) mcolor("$yo") lcolor("$yo") ///
		|| rcap upperCI_IW_m lowerCI_IW_m l_IW_m,  mcolor(navy) lcolor(navy %30) c(l) ///
		|| scatter IW_m l_IW_m , c(l) lw(thick)  m(S) graphreg(fc(white)) lpattern(longdash) mcolor(navy) lcolor(navy) ///		
			legend(order(2 "Never Move" 4 "Ever Moves" 6 "Moves Post") pos(6) row(1)) xtitle("Years from CBA Extension") ytitle("Estimate") 
	graph export $out/AS_mobility.png, replace
		
restore

			
*--> Figures in Appendix C: Cengiz et al. stacking method
	
clear	
do $do/QJE_R1/preamble_revision.do
replace logsalary = logsalary * 100
keep if timex > -6


*-----------------> Cengiz et al., stacked event studies
label var zero "0"

preserve
	keep if extension==2011|extension==2016|extension==2014
	g dataset=1
	tempfile s1
	save `s1', replace
restore	
preserve
	keep if extension==2012|extension==2016
	g dataset=2
	tempfile s2
	save `s2', replace
restore	

keep if extension==2013|extension==2016
g dataset=3

append using `s1'
append using `s2'

reghdfe logsalary femx_7-femx_9 zero femx_11-femx_13 female if timex > -4 & timex < 4, a($exp_c i.year##i.dataset i.year##i.extension##i.dataset) vce(cluster district_code)
	est store r1
coefplot (r1, lw(thick) lc("$ylb") recast(connect) ciopts(color("$ylb % 30"))), vert xline(4.5) graphreg(fc(white)) omitted xla(-4(1)4) title("Stacked (2011-2013 cohorts treated)", size(med)) ///
xtitle("time to CBA expiration/extension") ytitle("Coefficient") keep(femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13)
graph export $out/did_stacked_3.png, replace


reghdfe logsalary femx_6-femx_9 zero femx_11-femx_14 female if timex < 5 & ((dataset == 1 & extension != 2014) | dataset == 2), a($exp_c i.year##i.dataset i.year##i.extension##i.dataset) vce(cluster district_code)
	est store r1
coefplot (r1, lc("$ylb") lw(thick) recast(connect) ciopts(lc("$ylb % 30"))), vert xline(5.5) graphreg(fc(white)) omitted xla(-4(1)4) title("Stacked (2011-2012 cohorts treated)", size(med)) ///
xtitle("time to CBA expiration/extension") ytitle("Coefficient") keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero femx_11 femx_12 femx_13 femx_14)
graph export $out/did_stacked_2.png, replace


	
	
	
	
	
	
	
	
	
	
